﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using DynSim.EntityFramework;
using DynSim.Basics;

namespace DynSim.Entities
{
    [Serializable]
    public class BasicSprite : IEntity, IMoveable, IRotatable, IScalable, IHideable
    {
        public string name { get; set; }

        SpriteBatch batch;
        public Texture2D texture;
        public Vector3 position;
        public Vector3 rotation = new Vector3(0);
        public float scale = 1f;
        bool show = true;
        public Color color;

        public BasicSprite(string assetName, Color color, Vector3 position, BaseEngine engine, Game game, string name)
        {
            this.name = name;

            this.batch = new SpriteBatch(game.GraphicsDevice);
            this.texture = game.Content.Load<Texture2D>(assetName);
            this.position = position;
            this.color = color;
        }

        public BasicSprite(string assetName, Color color, Vector3 position, Vector3 rotation, BaseEngine engine, Game game, string name)
        {
            this.name = name;

            this.batch = new SpriteBatch(game.GraphicsDevice);
            this.texture = game.Content.Load<Texture2D>(assetName);
            this.position = position;
            this.rotation = rotation;
            this.color = color;
        }

        public BasicSprite(string assetName, Color color, Vector3 position, Vector3 rotation, float scale, BaseEngine engine, Game game, string name)
        {
            this.name = name;

            this.batch = new SpriteBatch(game.GraphicsDevice);
            this.texture = game.Content.Load<Texture2D>(assetName);
            this.position = position;
            this.rotation = rotation;
            this.scale = scale;
            this.color = color;
        }

        public void Initialize()
        {
            
        }

        public void Update(GameTime gameTime)
        {
            
        }

        public void Draw(GameTime gameTime)
        {
            if (show)
            {
                batch.Begin();

                float width = texture.Width * scale;
                float height = texture.Height * scale;
                batch.Draw(texture, new Rectangle(Int32.Parse(position.X.ToString()), Int32.Parse(position.Y.ToString()), Int32.Parse(width.ToString()), Int32.Parse(height.ToString())), color);

                batch.End();
            }
        }

        public void Move(Vector3 position)
        {
            this.position = position;
        }

        public void Rotate(Vector3 rotation)
        {
            this.rotation = rotation;
        }

        public void Scale(float value)
        {
            this.scale = value;
        }

        public void Show()
        {
            this.show = true;
        }

        public void Hide()
        {
            this.show = false;
        }
    }
}
